import request from '@/util/request'
import store from '@/vuex/store'
import config from "@/config/config";
import Axios from 'axios'

//查询要件列表
export function getDocumentListApi(applyCode) {
    const value = {
        appKey: '',
        appFlag: 2,
        token: store.getters.token,
        versionCode: 0,
        param: applyCode
    }
    return request({
        url: 'document/getDocumentList.do',
        method: 'post',
        data: value
    })
}

//删除文件
export function deleteDocumentApi(id) {
    const value = {
        appKey: '',
        appFlag: 2,
        token: store.getters.token,
        versionCode: 0,
        param: JSON.stringify(id)
    }
    return request({
        url: 'document/deleteDocument.do',
        method: 'post',
        data: value
    })
}
//查看告知书
export function lookTellBook(applyCode) {
    const value = {
        appKey: '',
        appFlag: 2,
        token: store.getters.token,
        versionCode: 0,
        param: applyCode
    }
    return request({
        url: 'document/lookTellBook.do',
        method: 'post',
        data: value
    })
}

//要件下载
export function downDocumentApi(id) {
    var params = new URLSearchParams();
    params.append('appKey', '');
    params.append('appFlag', 1);
    params.append('versionCode', 1);
    params.append('param', JSON.stringify(id));
    params.append("token", store.getters.token);
    window.location.href = (config.baseUrl + "/document/downDocument.do?params=" + params);

    // Axios.post(config.baseUrl + "/document/downDocument.do", params)
    // .then(function (res) {
    //     console.log(res)
    //     if(res.status == 200){

    //         const link = document.createElement('a')
    //         link.href = res.data;
    //         link.click() 
    //     }
    //     if(res.data.errCode == 504){
    //         alert(res.data.respondMessage)
    //     }
    // })
    // .catch(function (error) {
    //   this.$message({
    //     showClose: true,
    //     message: error,
    //     type: "error",
    //   });
    // });

}

//删除文件
export function deleteDocument(list) {
    const value = {
        appKey: '',
        appFlag: 2,
        token: store.getters.token,
        versionCode: 0,
        param: JSON.stringify(list)
    }
    return request({
        url: 'document/removeFile.do',
        method: 'post',
        data: value
    })
}
